//
//  XHNHudManager.m
//  PockPower
//
//  Created by 邢行 on 2017/7/3.
//  Copyright © 2017年 XingHang. All rights reserved.
//

#import "XHNHudManager.h"
#import "MBProgressHUD.h"

@implementation XHNHudManager


/**
 展示一个文字提示  toast
 
 @param msg 要显示的消息
 */
+(void)showWithText:(NSString *)msg{
    
    
    UIView *showView = [self showView];
    
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:showView animated:YES];
    hud.mode = MBProgressHUDModeText;
    hud.label.text = msg;
    hud.contentColor = [UIColor blackColor];
    hud.margin = 5;
    hud.label.textColor = [UIColor whiteColor];
    hud.offset = CGPointMake(0.f, 0);
    CGFloat durtion = 1.f;
//    hud.bezelView.backgroundColor = [UIColor redColor];
    
    //2,设置背景框的背景颜色和透明度， 设置背景颜色之后opacity属性的设置将会失效
    hud.bezelView.color = [[UIColor blackColor] colorWithAlphaComponent:1];
    hud.removeFromSuperViewOnHide=YES;
    [hud showAnimated:YES];
    hud.animationType = MBProgressHUDAnimationZoom;
    
    [hud hideAnimated:YES afterDelay:durtion];
   
    
    /** 总的背景颜色*/
    hud.backgroundView.backgroundColor = [UIColor clearColor];

    

}



/**
 展示一个文字提示  toast
 
 @param msg 要显示的消息
 */
+(void)showWithText:(NSString *)msg ctrl:(UIViewController *)actrl
{
    

    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:actrl.view animated:YES];
    hud.mode = MBProgressHUDModeText;
    hud.label.text = msg;
    hud.contentColor = [UIColor blackColor];
    hud.margin = 5;
    hud.label.textColor = [UIColor whiteColor];
    hud.offset = CGPointMake(0.f, 0);
    CGFloat durtion = 1.f;
    //    hud.bezelView.backgroundColor = [UIColor redColor];
    
    //2,设置背景框的背景颜色和透明度， 设置背景颜色之后opacity属性的设置将会失效
    hud.bezelView.color = [[UIColor blackColor] colorWithAlphaComponent:1];
    hud.removeFromSuperViewOnHide=YES;
    [hud showAnimated:YES];
    hud.animationType = MBProgressHUDAnimationZoom;
    
    [hud hideAnimated:YES afterDelay:durtion];
    
    
    /** 总的背景颜色*/
    hud.backgroundView.backgroundColor = [UIColor clearColor];
    
    
    
}


+(void)showWithText:(NSString *)msg durtion:(CGFloat)seconds{
    
    
    UIView *showView = [self showView];
    
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:showView animated:YES];
    hud.mode = MBProgressHUDModeText;
    hud.label.text = msg;
    hud.contentColor = [UIColor blackColor];
    hud.margin = 5;
    hud.label.textColor = [UIColor whiteColor];
    hud.offset = CGPointMake(0.f, 0);
    CGFloat durtion = seconds;
    
    [hud hideAnimated:YES afterDelay:durtion];
    
    
}



+(UIView*)showView{

    
    return [[UIApplication sharedApplication].windows lastObject];
    
    
}




@end


@implementation XHNHudManager (Loading)

//+(void)showLoadingWithText:(NSString *)msg {
//
//    UIView *showView = [self showView];
////
////    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:showView animated:YES];
////    hud.mode = MBProgressHUDModeText;
////    hud.label.text = msg;
////    hud.contentColor = [UIColor blackColor];
////    hud.margin = 5;
////    hud.label.textColor = [UIColor whiteColor];
////    hud.offset = CGPointMake(0.f, 0);
////    CGFloat durtion = 1;
////    
////    [hud hideAnimated:YES afterDelay:durtion];
//    
//
//}

@end
